# ！ /usr/bin/python3
# -*- coding:utf-8 -*-
# @Author:Peng Cao
# @File: 02opencv_video.py
# @Software: PyCharm

import cv2.cv2 as cv

vc = cv.VideoCapture('./data/1.mp4')  # 读取数据
print(vc)

if vc.isOpened():  # 判断视频文件能否打开
    open, img = vc.read()  # 读取视频文件第一帧以及第一帧图像
else:
    open = False
while open:
    ret, img = vc.read()
    if img is None:
        break
    if ret:
        gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
        cv.imshow('result', gray)
        if cv.waitKey(50) & 0xFF == 27:
            break
vc.release()
cv.destroyAllWindows()
